package com.bdqn.service.impl;


import com.bdqn.pojo.User;
import com.bdqn.repository.UserRepository;
import com.bdqn.service.UserService;
import com.bdqn.tools.Page;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class RoleServiceImpl implements UserService {

    private final UserRepository userRepository;

    public RoleServiceImpl(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public User login(String usrName, String usrPassword) {
        return null;
    }

    @Override
    public int saveUser(User user) {
        return 0;
    }

    @Override
    public int deleteUser(Long usrId) {
        return 0;
    }

    @Override
    public int updateUser(User user) {
        return 0;
    }

    @Override
    public User getUserById(Long usrId) {
        return null;
    }

    @Override
    public List<User> selectUsersWithRoles() {
        return List.of();
    }

    /**
     * 根据用户名查询用户
     *
     * @param usrName
     */
    @Override
    public User selectUserName(String usrName) {
        return null;
    }

    /**
     * 按条件进行分页查询（动态SQL）
     *
     * @param usrName
     * @param roleId
     * @param page
     */
    @Override
    public Page<User> findPage(String usrName, Long roleId, Page<User> page) {
        return null;
    }

    /**
     * 按条件进行分页查询（动态SQL）
     */
//    @Override
//    public Page<User> findUsers(String usrName, Long roleId, Pageable pageable) {
//        Specification<User> specififation = new Specification<User>() {
//            @Override
//            public Predicate toPredicate(Root<User> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
//                List<Predicate> predicates = new ArrayList<>();
//                if (usrName != null && ! usrName.equals("")) { // 用户名不为空
//                    predicates.add(criteriaBuilder.like(root.get("usrName"), "%" + usrName + "%"));
//                }
//                if (roleId != null && roleId.longValue() != 01) { // 角色不为空
//                    Role role = new Role();
//                    role.setRoleId(roleId);
//                    predicates.add(criteriaBuilder.equal(root.get("role"), role));
//                }
//
//                return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
//
//            }
//        };
//        return userRepository.findAll(specififation, pageable);
//    }
}
